<?php


/**
 * @author bebas
 * @version 1.0
 * @created 21-Mar-2013 15:15:38
 */
class User
{

	private $nip;
	private $nama;
	private $password;
	private $email;
	private $aktif;
	

	function __construct()
	{
	}
	
	function setNip($nip){
	
		$this->nip = $nip;
	}
	
	function setNama($nama){
	
		$this->nama = $nama;
	}
	
	function setPassword($password){
	
		$this->password = $password;
	}
	
	function setEmail($email){
	
		$this->email = $email;
	}
	
	function setAktif($aktif){
	
		$this->aktif = $aktif;
	}
	
	function getNip(){
	
		return $this->nip;
	}
	
	function getNama(){
	
		return $this->nama;
	}
	
	function getPassword(){
	
		return $this->password;
	}
	
	function getEmail(){
	
		return $this->email;
	}
	
	function getAktif(){
	
		return $this->aktif;
	}
	
}

class Daftar_user{

	function __construct()
	{
	}
	
	function getAll(){
		$sql="
		select *
		from
		user
		order by aktif desc, nip asc
		";
		
		$list_user = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$user = new User();
				$user->setNip($row['nip']);
				$user->setNama($row['nama']);
				$user->setAktif($row['aktif']);
				$user->setPassword($row['password']);
				$user->setEmail($row['email']);
					
				$list_user[] = $user;
			}
		}	
		return $list_user;
	}
	
	function getAktifUser(){
		$sql="
		select *
		from
		user
		where
		aktif = '1'
		";
		
		$list_user = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$user = new User();
				$user->setNip($row['nip']);
				$user->setNama($row['nama']);
				$user->setAktif($row['aktif']);
				$user->setPassword($row['password']);
				$user->setEmail($row['email']);
					
				$list_user[] = $user;
			}
		}	
		return $list_user;
	}
	
	function cek_user($nip,$password)
	{
		
		$sql="select count(*) as jml from user where nip='$nip' and password='$password' and aktif='1'";
        $query=mysql_query($sql);
        $data=mysql_fetch_assoc($query);
        $cek=false;
        if ($data['jml']>0){
          $cek=true;
        }
        return $cek;	
	}
	
	function getByNip($nip)
	{
		$sql="select * from user where nip='$nip'";
		$user=false;            
                $data = mysql_query($sql);
                if($data){
                        while($row = mysql_fetch_assoc($data)){
                                $user = new User();
                      
                                $user->setNip($row['nip']);
								$user->setNama($row['nama']);
								$user->setPassword($row['password']);
                                $user->setEmail($row['email']);
                                $user->setAktif($row['aktif']);
                        }
                }       
                return $user;

	
	}
	
	function edit(User $user){
		$sql="
		update 
		user 
		set 
		nama='".$user->getNama()."',
		email='".$user->getEmail()."',
		aktif='".$user->getAktif()."'
		where nip='".$user->getNip()."'
		";
		$query=mysql_query($sql);
		return $query;
	}
	
	function editPassword(User $user){
		$sql="
		update 
		user 
		set 
		password='".$user->getPassword()."'
		where nip='".$user->getNip()."'
		";
		$query=mysql_query($sql);
	}
	
	function add(User $user){
	
		$sql="
		insert into user(nip, nama, password, email, aktif)
		values(
		'".$user->getNip()."',
		'".$user->getNama()."',
		'".$user->getPassword()."',
		'".$user->getEmail()."',
		'".$user->getAktif()."'
	
		)
		";
		$query=mysql_query($sql);
		return $query;


	}

	function delete(User $user){
		$sql="
		delete 
		from
		user 
		where nip='".$user->getNip()."'
		";
		$query=mysql_query($sql);
		return $query;
	}	

}
?>